// pages/volunteer/activity/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    img:"https://img.yzcdn.cn/vant/cat.jpeg",
    list0:[],
    list1:[],
    currentpage0:0,
    currentpage1:0,
    query:{
      status:0,
      page:0
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const that = this
    if(that.data.active ==0) {
      that.data.currentpage0 = 0;
      that.setData({
        list0:[]
      });
      that.api_getRecord0();
    }
    else {
      that.data.list1 = [];
      // that.setData({
      //   list1:[]
      // });
      that.data.currentpage1 = 0;
      that.api_getRecord1();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const that = this
    if(that.data.active == 0) {
      that.api_getRecord0();
    }
    else {
      that.api_getRecord1();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onShareTimeline(){

  },
  onChangeTab(e) {
    console.log(e)
    const that = this
    that.setData({
      active:e.detail.name
    })
    if(e.detail.name == 0) {
      that.api_getRecord0();
    }
    else {
      that.api_getRecord1();
    }
  },
  api_getRecord0() {
    const that = this
    that.data.query.status = 0;
    that.data.query.page = that.data.currentpage0 + 1;
    app.api.get(app.getUrl('volunteer.record'), that.data.query).then((res)=>{
      if(res.data.length>0) {
        that.data.list0 = that.data.list0.concat(res.data);
        that.setData({
          list0:that.data.list0,
          currentpage0: res.pagination.current
        })
      }
    })
  },
  api_getRecord1() {
    const that = this
    that.data.query.status = 1;
    that.data.query.page = that.data.currentpage1 + 1;
    app.api.get(app.getUrl('volunteer.record'), that.data.query).then((res)=>{
      console.log(res)
      if(res.data.length>0) {
        that.data.list1 = that.data.list1.concat(res.data);
        that.setData({
          list1:that.data.list1,
          currentpage1: res.pagination.current
        })
      }
    })
  },
  doReview(e) {
    const that = this
    console.log(e)
    wx.navigateTo({
      url: '/pages/volunteer/review/index?aid='+e.currentTarget.dataset.aid,
    })
  }


})